﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.DrugTrade.BLLFactory;
using HZ.DrugTrade.IBLL;

namespace HZ.DrugTrade.Web.Hospitals.Procurement
{
    public partial class ProcureCatalogCompanyPS : BasePage
    {


        IBLL_Distribution id = Factory.BLL_Distribution();
        IBLL_HospitalProcureCatalog hpcCtrl = Factory.BLL_HospitalProcureCatalog();
        IBLL_ProcurementBasic pbCtrl = Factory.BLL_ProcurementBasic();

        protected void Page_Load(object sender, EventArgs e)
        {
            string procureCatalogId = Request.QueryString["procureCatalogId"];
            //by ligang 2009-6-15
            HZ.DrugTrade.Model.View.ProcureCatalog procureCatalog = pbCtrl.GetProcureCatalogByID(procureCatalogId);
            if (procureCatalog == null)
            {
                PageError("采购产品不存在！", "JavaScript:{history.go(-1);}");
            }
            else
            {
                //非采购产品单独设置配送企业 0 竞价议价，1重点监控，2，自行采购，3备案采购
                if (procureCatalog.SortSource.Value >= 3)
                {
                    PageInfo("备案采购产品可以任意选择配送企业。", "JavaScript:{history.go(-1);}");
                }
            }
 
            if (!IsPostBack)
            {
               
                BindAllCompanyList();
            }
        }

        /// <summary>
        /// 绑定所有可选的配送企业
        /// </summary>
        private void BindAllCompanyList()
        {
            string procureCatalogId = Request.QueryString["procureCatalogId"];
            string hospitalId = CurrentAccount.GetUser().Org.OrgID;
            //by ligang 2009-6-15
            HZ.DrugTrade.Model.View.ProcureCatalog hospitalProcureCatalog = pbCtrl.GetProcureCatalogByID(procureCatalogId);
            if (hospitalProcureCatalog != null)
            {
                this.lblGoodsName.Text = hospitalProcureCatalog.GoodsName;
                this.lblGg.Text = hospitalProcureCatalog.Outlookc;
                this.lblCompanyName_SC.Text = hospitalProcureCatalog.CompanyName_SC;
                this.lblCompanyName_ZB.Text = hospitalProcureCatalog.CompanyName_TB;
                this.lblBidPrice.Text = (hospitalProcureCatalog.ProcurePrice.Value == 0) ? "NA" : hospitalProcureCatalog.ProcurePrice.Value.ToString("0.00");
            }

            //获取该采购目录所有可配送企业
            int count;
            IList<Model.View.AreaDistribution> availableList = id.GetPartDistribution(procureCatalogId, hospitalId, 1, 0, out count);

            gvwCompany.DataSource = availableList;
            gvwCompany.DataBind();
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            BindAllCompanyList();
        }
        
    }
}
